package nl.moviefan.site.model;

import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import java.util.List;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

/**
 * User is a SQL-reserved word, for that reason we decided to rename User to
 * MoviefanUser.
 */
@Entity
@Table(name = "moviefan_users")
public class MoviefanUser implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "moviefan_user_id")
    private long id;

    @Column(name = "username")
    @NotNull
    private String username;

    @Column(name = "ww")
    @NotNull
    private String password;

    @Transient
    private String passwordConfirm;

    @Column(name = "enabled")
    @NotNull
    private boolean enabled;

    @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
    @JoinTable(name = "moviefan_user_roles",
            joinColumns = {
                @JoinColumn(name = "moviefan_user_fk")},
            inverseJoinColumns = {
                @JoinColumn(name = "moviefan_role_fk")})
    private List<MoviefanRole> moviefanUserRoles;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public List<MoviefanRole> getMoviefanUserRoles() {
        return moviefanUserRoles;
    }

    public void setMoviefanUserRoles(List<MoviefanRole> moviefanUserRoles) {
        this.moviefanUserRoles = moviefanUserRoles;
    }

    public String getPasswordConfirm() {
        return passwordConfirm;
    }

    public void setPasswordConfirm(String passwordConfirm) {
        this.passwordConfirm = passwordConfirm;
    }

}
